var fileHelper = (function () {  
    function download(file, txt) {
        var blob = stringToBlob(txt);
        var aLink = document.createElement('a');
        var evt = document.createEvent("MouseEvents");
        evt.initEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
        aLink.download = file + '.txt';
        aLink.href = URL.createObjectURL(blob);
        aLink.dispatchEvent(evt);
    }
    function stringToBlob(text) {
        var u8arr = new Uint8Array(text.length);
        for (var i = 0; i < text.length; i++) {
            u8arr[i] = text.charCodeAt(i);
        }
        var blob = new Blob([u8arr]);
        return blob;
    }
    function upload(file, fn) {
        var reader = new FileReader();     
        reader.readAsText(file);
        reader.onload = function (e) {
            fn(this.result);
        }
    }
    return { 
        'download': download,
        'upload': upload
    };
})();
